/**
 * Created by PanShiChao on 2016/12/26.
 */
$(document).ready(function() {
    $("#gaoliang0").removeClass("sub-menu-link").addClass("selected");
    window.random_code_index = 0;
    $("#defButton").click(function() {
        var randomN = getRandomNum();
        $("#merOrderNum").val(randomN);

    });

    //商户订单号
    $("#merOrderNum").val(getRandomNum());

    $.formValidator.initConfig({
        validatorgroup : "1",
        formid : "form",
        onerror : function(input1, input2) {
            return false;
        }
    });

    $("#tranCode").formValidator({
        onshow : " "
    }).inputValidator({
        min : 1,
        onerror : "交易码不允许为空！"
    }).functionValidator({
        fun : function(val) {
            if (val != "DS02") {
                return "交易码必须为 DS02";
            } else {
                return true;
            }
        }
    });

    $("#merchantID").formValidator({
        onshow : " "
    }).inputValidator({
        min : 1,
        onerror : "企业ID不允许为空！"
    });

    $("#merOrderNum").formValidator({
        onshow : " "
    }).inputValidator({
        min : 1,
        onerror : "订单号不允许为空！"
    });

    $("#oldMerOrderId").formValidator({
        onshow : " "
    }).inputValidator({
        min : 1,
        onerror : "原鉴权订单号不能为空！"
    });

    $("#tranDateTime").formValidator({
        onshow : " "
    }).inputValidator({
        min : 1,
        onerror : "交易时间不允许为空！"
    });


});

function getRandomNum() {
    window.random_code_base = (([ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J',
            'K', 'M', 'N' ])[new Date().getMonth()])
        + '_' + (Math.random() * 10000000000 + '').substring(0, 4);
    return window.random_code_base + "_" + (window.random_code_index++);
}